package com.jinsilu.freight.ui.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.jinsilu.freight.R;
import com.jinsilu.freight.http.response.VehicleListBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * 车辆列表信息
 *
 * @author yangyang
 * @time 2020-11-10 16:00
 */
public class VehicleListAdapter extends BaseQuickAdapter<VehicleListBean, BaseViewHolder> {

    public VehicleListAdapter(@Nullable List<VehicleListBean> data) {
        super(R.layout.item_vehicle_list, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, VehicleListBean s) {
        holder.setText(R.id.vehicle_plate_number, s.getPlateNumber());
        setVehicleStatusBg(holder, s.getAuthStatus());
        isDefaultVehicle(holder, s.getDefaultVehicle().equals("1")); // 1 - 默认 0 - 非默认
    }

    /**
     * 是否为默认车辆
     */
    private void isDefaultVehicle(@NotNull BaseViewHolder holder, boolean isDefault) {
        if (isDefault) {
            holder.setVisible(R.id.default_vehicle_ic, true)
                    .setVisible(R.id.default_vehicle_text, true);
        } else {
            holder.setGone(R.id.default_vehicle_ic, true)
                    .setGone(R.id.default_vehicle_text, true);
        }
    }

    /**
     * 车辆审核状态
     */
    private void setVehicleStatusBg(@NotNull BaseViewHolder holder, String status) {
        if ("-1".equals(status)) { // 未认证
            holder.setBackgroundResource(R.id.vehicle_status, R.drawable.shape_vehicle_uncertified_bg)
                    .setText(R.id.vehicle_status, "未认证");
        } else if ("1".equals(status)) { // 审核通过
            holder.setBackgroundResource(R.id.vehicle_status, R.drawable.shape_vehicle_certified_bg)
                    .setText(R.id.vehicle_status, "已认证");
        } else if ("0".equals(status)) { // 审核中···
            holder.setBackgroundResource(R.id.vehicle_status, R.drawable.shape_vehicle_uncertified_bg)
                    .setText(R.id.vehicle_status, "认证失败");
        } else if ("2".equals(status)){
            holder.setBackgroundResource(R.id.vehicle_status, R.drawable.shape_vehicle_check_pending_bg)
                    .setText(R.id.vehicle_status, "待审核");
        }
    }
}
